//
//  GXShopAuthenViewCell.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/11/28.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXShopAuthenViewCell.h"
#import "GXBasicInformationController.h"
#import "GXBussinessTimeController.h"
#import "GXShopIntroduceController.h"
#import "GXServiceViewController.h"
#import "GXShopPictureController.h"
#import "GXShopBGViewController.h"
#import "ImagePickerTool.h"
#import "OrderAndUploadPhotoMananger.h"
@interface GXShopAuthenViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *baseMessageLabel;
@property (weak, nonatomic) IBOutlet UILabel *shopIntroduceLabel;
@property (weak, nonatomic) IBOutlet UILabel *openShopLabel;
@property (weak, nonatomic) IBOutlet UILabel *serviceLabel;
@property (weak, nonatomic) IBOutlet UILabel *shopPhotoLabel;
@property (weak, nonatomic) IBOutlet UILabel *shopBGLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (copy, nonatomic) NSString *coverImageStr;


@end
@implementation GXShopAuthenViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveAddBackImageMessage:) name:@"addShopPicture" object:nil];
    [self setViewsValue];
}
- (void)receiveAddBackImageMessage:(NSNotification *)notifi
{
    MyLog(@"addShopPicture");
    self.shopPhotoLabel.text = @"完成";
}
- (void)setViewsValue
{
    NSDictionary * contentDic = [NSDictionary dictionaryWithDictionary: [[NSUserDefaults standardUserDefaults] objectForKey:@"ShopDetail"]];
    NSString * coverStr = [NSString stringWithFormat:@"%@",contentDic[@"cover"]];
    NSString * headUrlStr = [NSString stringWithFormat:@"%@/%@",kBaseURLIMAGE,coverStr];//封面
    self.coverImageStr =coverStr;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:headUrlStr] placeholderImage:[UIImage imageNamed:@"placeholder_cover"]];
    NSString * addressStr =[NSString stringWithFormat:@"%@",contentDic[@"address"]];//地址
    NSString * introduceStr = [NSString stringWithFormat:@"%@",contentDic[@"introduce"]];//简介
    NSString * bussinessStr = [NSString stringWithFormat:@"%@",contentDic[@"businesstime"]];//营业时间
    NSString * serviceStr = [NSString stringWithFormat:@"%@",contentDic[@"serviceSige"]];//服务
    NSString * storeImageStr =[NSString stringWithFormat:@"%@",contentDic[@"storeImage"]];//实景图
    NSString * backImageStr = [NSString stringWithFormat:@"%@",contentDic[@"backImage"]];//背景图
    [self judgeAuthFromStr:addressStr UILabel:self.baseMessageLabel];
    [self judgeAuthFromStr:introduceStr UILabel:self.shopIntroduceLabel];
    [self judgeAuthFromStr:bussinessStr UILabel:self.openShopLabel];
    [self judgeAuthFromStr:serviceStr UILabel:self.serviceLabel];
    [self judgeAuthFromStr:storeImageStr UILabel:self.shopPhotoLabel];
    [self judgeAuthFromStr:backImageStr UILabel:self.shopBGLabel];
}

- (void)judgeAuthFromStr:(NSString *)str UILabel:(UILabel *)label
{
    if ([NSString isBlankString:str]) {
        label.text = @"未完成";
    }else{
        label.text = @"完成";
    }
}

- (IBAction)pressRequestPhotoBtn:(id)sender {
    [[ImagePickerTool sharePicker] showImagePicker:self.getViewController allowEdit:YES complete:^(id param) {
        [OrderAndUploadPhotoMananger uploadPhotoToServerFromImage:param fileName:Cover success:^(id responseObject) {
            if (responseObject) {
                self.headImageView.image = param;
               self.coverImageStr = responseObject[@"describa"];
            }
        } fail:^(id responseObject) {
        }];
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
- (IBAction)pressBtnClick:(UIButton *)sender {
    WeakSelf(weakSelf);
    if (sender.tag ==41) {
        [self jumpController:[GXBasicInformationController class]];
    }else if (sender.tag ==42){
        GXShopIntroduceController * introduceVC = [[GXShopIntroduceController alloc]init];
        introduceVC.changeStateBlock = ^(BOOL stateType) {
            weakSelf.shopIntroduceLabel.text = @"完成";
        };
        [self.getViewController.navigationController pushViewController:introduceVC animated:YES];
    }else if (sender.tag ==43){
        GXBussinessTimeController * bussniessVC = [[GXBussinessTimeController alloc]init];
        bussniessVC.changeBussTimeBlock = ^(BOOL stateType) {
            weakSelf.openShopLabel.text =@"完成";
        };
        [self.getViewController.navigationController pushViewController:bussniessVC animated:YES];
    }else if (sender.tag ==44){
        GXServiceViewController * serviceVC = [[GXServiceViewController alloc]init];
        serviceVC.changeServiceBlock = ^(BOOL stateType) {
            weakSelf.serviceLabel.text =@"完成";
        };
        [self.getViewController.navigationController pushViewController:serviceVC animated:YES];
    }else if (sender.tag ==45){
        [self jumpController:[GXShopPictureController class]];
    }else{
        GXShopBGViewController * backImageVC = [[GXShopBGViewController alloc]init];
        backImageVC.changeBackImageBlock = ^(BOOL stateType) {
            self.shopBGLabel.text =@"完成";
        };
        [self.getViewController.navigationController pushViewController:backImageVC animated:YES];
    }
}
- (IBAction)pressConmmitBtn:(UIButton *)sender {
    if (![self judgeLabelValue]) {
        return;
    }
    [ShopAuthenticationManager commitShopCheckWithStoreID:StoreId success:^(id responseObject) {
        MyLog(@"提交成功");
    } fail:^(id responseObject) {
        
    }];
}
- (BOOL)judgeLabelValue
{
    if ([NSString isBlankString:self.coverImageStr]) {
        [SVProgressHUD showErrorWithStatus:@"请上传封面照片"];
        return NO;
    }
    if ([NSString isBlankString:self.shopIntroduceLabel.text]) {
        [SVProgressHUD showErrorWithStatus:@"请完成店铺简介"];
        return NO;
    }
    if ([NSString isBlankString:self.openShopLabel.text]) {
        [SVProgressHUD showErrorWithStatus:@"请选择店铺营业时间"];
        return NO;
    }
    if ([NSString isBlankString:self.serviceLabel.text]) {
        [SVProgressHUD showErrorWithStatus:@"请选择店铺服务"];
        return NO;
    }
    if ([NSString isBlankString:self.shopPhotoLabel.text]) {
        [SVProgressHUD showErrorWithStatus:@"请完成店铺实景图"];
        return NO;
    }
    if ([NSString isBlankString:self.shopBGLabel.text]) {
        [SVProgressHUD showErrorWithStatus:@"请完成店铺背景图"];
        return NO;
    }
    return YES;
}


#pragma 跳转到对应的控制器
-(void)jumpController:(Class)VC
{
    UIViewController * controller = [[VC alloc]init];
    [self.getViewController.navigationController pushViewController:controller animated:YES];
}
@end
